<?php

namespace app\admin\controller;

use think\Controller;
use Util\SysDb;
use think\Db;
class Sensitive extends Controller
{
    public function sensitivelist()
    {
        $page = trim(input('param.pageNo'));
        $limit = trim(input('param.pageSize'));
        $sensitiveStr= trim(input('param.sensitiveStr'));
        $tol = (intval($page) - 1) * $limit;
        $where=array(
            "sensitive_str" => $sensitiveStr,
        );
        foreach ($where as $key=>$value)
        {
            if(empty($value)){
                unset($where[$key]);
            }
        }
        $list = DB::name("sys_sensitive")->order("create_time desc")->where($where)->limit($tol, $limit)->select();
        $this->db = new SysDb();
        $count = $this->db->table('sys_sensitive')->where($where)->count();
        $data = array();
        array_push($data, $list);
        array_push($data, $count);
        exit(json_encode(['code' => 1, 'message' => 'succ', "result" => $data]));
    }
    public function addSensitive(){
        $sensitiveStr = trim(input('param.sensitiveStr'));
        $this->db = new SysDb();
        $admin['sensitive_str']= $sensitiveStr;
        $count = $this->db->table('sys_sensitive')->insert($admin);
        if($count){
            exit(json_encode(['code' => 1, 'message' => 'succ', "result" => "添加成功"]));
        }
    }
    public function updateSensitive(){
        $sensitiveStr = trim(input('param.sensitiveStr2'));
        $status=trim(input('param.status'));
        $id=trim(input('param.id'));
        $this->db = new SysDb();
        $admin=$this->db->table('sys_sensitive')->where(['id' => $id])->item();
        $admin['sensitive_str']= $sensitiveStr;
        $admin['status']= $status;
        $count = $this->db->table('sys_sensitive')->where(['id' => $id])->update($admin);
        if($count){
            exit(json_encode(['code' => 1, 'message' => 'succ', "result" => "添加成功"]));
        }
    }
    public function Sensitivedel(){
        $id=trim(input('param.id'));
        $admin = Db::name('sys_sensitive')->where('id', $id)->delete();;
        if( $admin){
            exit(json_encode(['code' => 1, 'message' => 'succ', "result" => "添加成功"]));
        }
    }
    
}
